package leetcode;

import java.util.Collections;
import java.util.PriorityQueue;

public class Lc215 {


    public int findKthLargest(int[] nums, int k) {
        PriorityQueue<Integer> queue = new PriorityQueue<>(Collections.reverseOrder());
        for (int i = 0; i < nums.length; i++) {
            queue.offer(nums[i]);
            if (queue.size() > k)
                queue.poll();
        }
        return queue.peek();
    }

}
